//
// Created by liushuai on 2020/3/16.
//
#include <vector>
#include <string>

std::string longestCommonPrefix(std::vector<std::string> &strs) {
    int min_size = 1000;
    std::string comm = "";
    for (auto &&e:strs) {
        if (e.size() < min_size)
            min_size = e.size();
    }
    if (min_size <= 0 | strs.size() <= 0)
        return comm;
    else {
        for (int i = 0; i < min_size; i++) {
            char first_char = strs.at(0).at(i);
            for (int j = 1; j < strs.size(); j++) {//遍历每个字符串的第i的元素
                std::string currentStr = strs.at(j);
                char currentChar = currentStr.at(i);
                if (first_char == currentChar)
                    continue;
                else
                    return comm;

            }
            comm += first_char;
        }
        return comm;
    }

}
